<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <include file="./Public/Admin/header.html" />
    <script type="text/javascript" src="__PUBLIC__js/jquery_wookmark_min.js?2013-10-15-2"></script>
    <script type="text/javascript" src="__PUBLIC__js/masonry.pkgd.min.js?2013-10-15-2"></script>
    <script type="text/javascript" src="__PUBLIC__js/jquery_imagesloaded.js?2013-10-15-2"></script>
    <script type="text/javascript" src="__PUBLIC__js/jquery.pagination.js?2013-10-15-2"></script>
    <link rel="stylesheet" type="text/css" href="__PUBLIC__css/emotion.css?2013-10-15-2" media="all" />
    <script type="text/javascript" src="__PUBLIC__js/emotion.js?2013-10-15-2"></script>
</head>
<body>
<div id="main">
    <div class="container-fluid">

        <div class="row-fluid">
            <div class="span12">

                <div class="box">


                    <div class="box-title">
                        <div class="span4">
                            <h3><i class="icon-table"></i>关键词回复</h3>
                        </div>
                        <div class="btn-group pull-right clearfix ">
                            <form action="Admin/home/replykeyword" method="get" class="form-horizontal" style="margin: 0px;">
                                <input type="text" id="keyword" name="keyword" value="<?php echo isset($keyword)?$keyword:''?>" class="input-small-z" placeholder="请输入关键词" />

                                <button class="btn" id="btn_search">查询</button>
                            </form>
                        </div>
                    </div>

                    <div class="box-content nozypadding">
                        <div class="row-fluid">
                            <div class="span8 control-group">
                                <div class="span3">
                                    <a class="btn" href="{:U('Admin/Wechat/editkeyword')}?action=add"><i class="icon-plus"></i>添加</a>
                                    <a class="btn" href="javascript:location.reload();"><i class="icon-refresh"></i>刷新</a>
                                </div>

                                <div class="span9 datatabletool">

                                    <div class="btn-group">
                                        <a class="btn" attr="BatchDel" title="删除"><i class="icon-trash"></i>删除</a>
                                    </div>
                                </div>

                            </div>


                        </div>

                        <div class="row-fluid dataTables_wrapper">
                            <table id="listTable" class="table table-hover table-nomargin table-bordered usertable dataTable">
                                <thead>
                                <tr>
                                    <th class='with-checkbox'>
                                        <input type="checkbox" class="check_all"></th>
                                    <th>关键词</th>
                                    <th>回复</th>
                                    <th>时间</th>
                                    <th>操作</th>
                                </tr>

                                </thead>
                                <tbody>
                                <foreach name="contents" item="item">
                                <tr>
                                    <td class="with-checkbox">
                                        <input type="checkbox" name="check" value="{$item['replyid']}">
                                    </td>
                                    <td>{$item['keyname']}</td>
                                    <td><?php echo $item['wechat_contents']['contenttype']=='text'?'文本':'图文'?>&nbsp;<a href="javascript:void(0);" data-rid="{$item['replyid']}" data-cid="{$item['contentid']}"  class="btn btn-mini viewreply" rel="tooltip" title="查看"><i class="icon-search"></i></a></td>
                                    <td>{$item['addtime']}</td>
                                    <td class='hidden-480'>

                                        <a href="{:U('Admin/Wechat/editkeyword')}?action=edit&rid={$item['replyid']}" class="btn" rel="tooltip" title="修改"><i class="icon-edit"></i></a>
                                        <a href="javascript:void(0);" class="btn" rel="tooltip" title="删除" attr="deltext_{$item['replyid']}"><i class="icon-remove"></i></a>
                                    </td>
                                </tr>
                                </foreach>
                                </tbody>

                            </table>

                            <div class="row-fluid">
                                <div class="span4">
                                    <div class="dataTables_info">
                                        <if condition="$total gt 0">
                                            共{$total}条记录，当前第{$nowPage}/{$totalPages}页
                                        </if>
                                    </div>
                                </div>
                                <div class="span8">
                                    <div class="dataTables_paginate paging_full_numbers">
                                        <span>
                                            {$page}
                                        </span>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

        </div>
    </div>
</div>

<script type="text/javascript">
    Emotion.url='__PUBLIC__img/face/';
    $(function(){
        var delText = function(event){
            G.ui.tips.confirm_flag('您确定要删除吗?',function(){

                $.post("{:U('Admin/Wechat/delreply')}", {ids:event.data.rid},function(data){
                    if (data.errno ==0)
                    {
                        location.reload();
                    } else {
                        G.ui.tips.err(data.error);
                    }
                },'json');
            });
        };

        $("a[attr^='deltext_']").each(function(){
            var tmp = $(this).attr('attr').split('_');
            var id = new Array();
            id[0]=tmp[1];
            $(this).bind("click", {rid:id}, delText);
        });


        $("[attr='BatchDel']").click(function(){
            var check = $("input:checked").not($(".check_all")[0]);
            if(check.length<1){
                alert('请选择删除项');
                return false;
            }

            G.ui.tips.confirm_flag('您确定要删除吗?',function(){
                var id = new Array();
                check.each(function(i){
                    id[i] = $(this).val();
                });
                $.post("{:U('Admin/Wechat/delreply')}", {ids:id},function(data){

                    if (data.errno ==0)
                    {
                        location.reload();
                    } else {
                        G.ui.tips.err(data.error);
                        //alert(data.error);
                    }
                },'json');
            });
        });
        /*
         $("#btn_search").click(function(){
         var keywords = $.trim($('#keyword').val());
         if (keywords.length <= 0) {
         alert('请输入搜索关键字.');
         $('#keyword').focus();
         return false;
         }
         });*/

        $("#keyword").keyup(function(e) {
            if (e.keyCode == 13) {
                $("#btn_search").click();
                return false;
            }
        });
        var sel_rid='';
        $(".viewreply").each(function(){
            //var tmp = $(this).attr('attr').split('_');
            var cid=$(this).attr('data-cid');
            var rid=$(this).attr('data-rid');
            $(this).bind("click", {cid:cid,rid:rid}, viewReply);
        });
        function viewReply(event){
            //alert(event.data.cid);
            var cid=event.data.cid;
            sel_rid=event.data.rid;
            var rtype='textkey';
            $.get("{:U('Admin/Wechat/getcontent')}",{type:rtype,cid:cid},function(data){
                $('#myModal').modal('show');
                var str='';
                var item=data;
                if(data.contenttype=='news'){
                    var conitem=eval("("+item.content+")");//内容转换为json对象
                    if(conitem.length==1){
                    //单图文
                        str+='<div class="item_news">'
                        +'<div class="imgEdit " id="imgEdit">'
                        +' <div  id="item_0">'
                        +'  <div class="caption div_caption" >'+conitem[0].detailtitle+' </div>'
                        +' <div class="time">'+item.addtime+'</div>'
                        +'<div class="img"><div class="coverImg">'
                        +' <img  src="'+conitem[0].detaillogo+'" />'
                        +'</div></div>'
                        +'<div class="des">'+conitem[0].detailintro+'</div></div>'
                        +' </div></div>';
                    }else{
                    //多图文
                        str+='<div class="item_news">'
                        +' <div class="imgsEdit " id="imgsEdit">'
                        +'                     <div class="time">'+item.addtime+'</div>'
                        +'                    <div class="img" id="item_0">'
                        +'                        <div class="coverImg"><img src="'+conitem[0].detaillogo+'"/></div>'
                        +'                        <div class="caption" style=" ">'
                        +'                            <span  class="div_caption" >'+conitem[0].detailtitle+' </span>'
                        +'                       </div>'
                        +'                   </div>'
                        +'                   <ul class="unstyled">';
                        for(var i=1;i<conitem.length;i++){
                            str+='    <li class="item">'
                            +'       <div class="caption div_caption">'+conitem[i].detailtitle+' </div>'
                            +'     <div class="itemImg coverImg"><img src="'+conitem[i].detaillogo+'"/></div>'
                            +'     <div class="div_content hide"></div>'
                            +' </li>';
                        }
                        str+='     </ul> ';
                        str+=' </div>  </div>';
                    }
                }else{
                    var c=Emotion.replaceEmoji(item.content);
                    c=c.replace(/&lt;/gi, "<").replace(/&gt;/gi, ">");
                    str+='<div class="item_news">'
                    +'                <div class="imgEdit" id="imgEdit">'
                    +'                        <div  id="item_0">'
                    +'                            <div class="time">'+item.addtime+'</div>'
                    +'                            <div class="des" style="">'+c+'</div>   '
                    +' </div> '
                    +' </div>  </div>';
                }
                str+='<br />';
                $('#content-panel').html(str);
            },'json');
        };

        $('#edit_reply').click(function(){
            if(sel_rid!=''){
                var url="{:U('Admin/Wechat/editkeyword')}?action=edit&rid="+sel_rid;
                window.location.href=url;
            }
        })

    });
</script>
<div id="myModal" style="width: 380px;" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">

            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title"><i class="icon-search"></i> 查看回复</h4>
            </div>
            <div class="modal-body">
                <div class="row-fluid" id="content-panel">

                </div>

            </div>
            <div class="modal-footer">
                <a href="javascript:;" class="btn btn-primary" rel="tooltip" id="edit_reply" title="修改"><i class="icon-edit"></i>修改回复</a>
                <button type="button" class="btn btn-primary hide" id="btn-setmanage" data-dismiss="modal">确定</button>
            </div>


        </div>
        <!-- /.modal-content -->
    </div>
    <!-- /.modal-dialog -->
</div>

</body>
</html>
